Locate

In [1]:
locate grub.cfg
/boot/grub/grub.cfg
/usr/share/doc/grub-common/examples/grub.cfg
In [2]:
whatis updatedb
updatedb (8)         - update a database for mlocate
In [1]:
cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs /var/lib/schroot"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs ecryptfs fusesmb devtmpfs"
In [3]:
which locate
/usr/bin/locate
In [5]:
ll `which locate`
lrwxrwxrwx 1 root root 24 Aug  7 20:56 /usr/bin/locate -> /etc/alternatives/locate*
In [6]:
ll /etc/alternatives/locate
lrwxrwxrwx 1 root root 16 Aug  7 20:56 /etc/alternatives/locate -> /usr/bin/mlocate*
In [7]:
whatis mlocate
mlocate (1)          - find files by name
In [8]:
whatis locate
locate (1)           - find files by name

Find

In [43]:
find -iname fhs*
./Downloads/fhs-2.3.pdf
In [45]:
find -name FHS*
In [46]:
find -iname FHS*
./Downloads/fhs-2.3.pdf
In [2]:
#find -size +200M
#find -inum 122223 -gid 
#find -atime +1 -mtime +1
#find -type f # f c b l d 
#find /path -para
In [20]:
ls a/
10.html  8  8.html  9.html  w  x  y  z
In [25]:
find a/ ! -iname '*.html' -type f
a/8
a/z
a/x
a/w
a/y
In [26]:
find a/ -iname '[1-9]'
a/8
In [29]:
find /dev -type c | head -5
/dev/watchdog0
/dev/watchdog
/dev/hidraw0
/dev/vboxnetctl
/dev/vboxdrvu
In [45]:
find /dev -type c | head
/dev/watchdog0
/dev/watchdog
/dev/hidraw0
/dev/vboxnetctl
/dev/vboxdrvu
/dev/vboxdrv
/dev/video0
/dev/media0
/dev/vboxusb/003/003
/dev/vboxusb/003/002
In [ ]:
find /dev -type b -exec ls -lhtr {} \;
brw-rw---- 1 root disk 252, 3 Dec 24 11:39 /dev/dm-3 brw-rw---- 1 root disk 252, 2 Dec 24 11:39 /dev/dm-2 brw-rw---- 1 root disk 252, 1 Dec 24 11:39 /dev/dm-1 brw-rw---- 1 root disk 252, 0 Dec 24 11:39 /dev/dm-0 brw-rw---- 1 root disk 8, 5 Dec 24 11:39 /dev/sda5 brw-rw---- 1 root disk 8, 2 Dec 24 11:39 /dev/sda2 brw-rw---- 1 root disk 8, 1 Dec 24 11:39 /dev/sda1 brw-rw----+ 1 root cdrom 11, 0 Dec 24 11:39 /dev/sr0 brw-rw---- 1 root disk 8, 0 Dec 24 11:39 /dev/sda brw-rw---- 1 root disk 7, 7 Dec 24 11:39 /dev/loop7
In [3]:
# Will runs the command for each file
find /dev -type f -exec echo {} Milad \;
/dev/shm/pulse-shm-3708256176 Milad
/dev/shm/pulse-shm-745853968 Milad
/dev/shm/pulse-shm-3796149152 Milad
/dev/shm/sem.lastpassffsemaphore Milad
/dev/shm/pulse-shm-2242611167 Milad
/dev/shm/pulse-shm-882805694 Milad
/dev/shm/pulse-shm-1326275543 Milad
In [53]:
find /dev -name sda1 -or -name sda2
/dev/sda2
/dev/sda1
In [2]:
# find / -mtime +10 –mtime -20
# find ~ ! -path '*/\.*' -perm 764 -exec chmod 664 {} \;
# find ~ ! -path '*/\.*' -perm 764 -type f -exec chmod 664 {} \;

Important permissions

In [1]:
cd /usr/bin
In [2]:
find -perm 4000 # exactly 4000 - having exactly a 4 and others should be 000
In [5]:
find -perm -4000 -exec ls --color -l {} \; # having 4 is necessary - others does not matter
-rwsr-xr-x 1 root root 49584 Mar 29  2016 ./chfn
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 ./at
-rwsr-xr-x 1 root root 54256 Mar 29  2016 ./passwd
-rwsr-xr-x 1 root root 40432 Mar 29  2016 ./chsh
-rwsr-xr-x 1 root root 39904 Mar 29  2016 ./newgrp
-rwsr-xr-x 1 root root 75304 Mar 29  2016 ./gpasswd
-rwsr-xr-x 1 root root 23376 Jan 18  2016 ./pkexec
-rwsr-xr-x 1 root root 136808 Jan 20 19:34 ./sudo
In [6]:
find -perm -6000 -exec ls --color -l {} \; # having 4 and 2 is necessary - others does not matter
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 ./at
In [9]:
find -perm -2000 -exec ls --color -l {} \; # having 2 is necessary - others does not matter
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 ./at
-rwxr-sr-x 1 root tty 27368 Dec 16 19:10 ./wall
-rwxr-sr-x 1 root crontab 36080 Apr  6  2016 ./crontab
-rwxr-sr-x 1 root shadow 62336 Mar 29  2016 ./chage
-rwxr-sr-x 1 root mlocate 39520 Nov 18  2014 ./mlocate
-rwxr-sr-x 1 root ssh 358624 Aug 11  2016 ./ssh-agent
-rwxr-sr-x 1 root shadow 22768 Mar 29  2016 ./expiry
-rwxr-sr-x 1 root tty 14752 Mar  1  2016 ./bsd-write
-rwxr-sr-x 1 root utmp 434216 Feb  7  2016 ./screen
In [10]:
find -perm /6000 -exec ls --color -l {} \; # having 2 OR 4 OR both is necessary - others does not matter
-rwsr-xr-x 1 root root 49584 Mar 29  2016 ./chfn
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 ./at
-rwsr-xr-x 1 root root 54256 Mar 29  2016 ./passwd
-rwxr-sr-x 1 root tty 27368 Dec 16 19:10 ./wall
-rwsr-xr-x 1 root root 40432 Mar 29  2016 ./chsh
-rwxr-sr-x 1 root crontab 36080 Apr  6  2016 ./crontab
-rwxr-sr-x 1 root shadow 62336 Mar 29  2016 ./chage
-rwsr-xr-x 1 root root 39904 Mar 29  2016 ./newgrp
-rwxr-sr-x 1 root mlocate 39520 Nov 18  2014 ./mlocate
-rwxr-sr-x 1 root ssh 358624 Aug 11  2016 ./ssh-agent
-rwxr-sr-x 1 root shadow 22768 Mar 29  2016 ./expiry
-rwsr-xr-x 1 root root 75304 Mar 29  2016 ./gpasswd
-rwsr-xr-x 1 root root 23376 Jan 18  2016 ./pkexec
-rwxr-sr-x 1 root tty 14752 Mar  1  2016 ./bsd-write
-rwxr-sr-x 1 root utmp 434216 Feb  7  2016 ./screen
-rwsr-xr-x 1 root root 136808 Jan 20 19:34 ./sudo
In [15]:
find / -maxdepth 1 -perm /3000 -exec ls --color -dl {} \; # having 2 OR 1 OR both is necessary - others does not matter
drwxrwxrwt 12 root root 12288 Mar  5 14:45 /tmp
In [1]:
find /usr/bin/ ! -user root -perm /6000 -exec ls -l --color {} \;
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 /usr/bin/at
In [2]:
find /usr/local/ -nouser

Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github